import ProTable from '@ant-design/pro-table';

const GTable = (props) => {
  const { request, columns } = props

  //获取转换枚举
  let columnData = columns.map((v, k) => {
    if (v.optionsData && v.optionsData.length > 0) {
      const [value = 'value', label = 'label'] = v.models || [];
      v.valueEnum = {}
      for (let i in v.optionsData) {
        v.valueEnum[v.optionsData[i][value]] = v.optionsData[i][label]
      }
    }
    return v
  })

  const tableProps = {
    ...props,
    columns: columnData
  }

  return (
    <ProTable
      {...tableProps}
      request={(params) => request({ ...params, }).then(({ code, data = {} }) => {
        const { list = [], pageSize, current, total } = data;
        const result = {
          data: list,
          total,
          success: code === 200 ? true : false,
          pageSize,
          current
        }
        return result
      })}
    />
  );
};

export default GTable;